package com.github.lee.mvvm.core.ui.web

import android.graphics.Bitmap
import com.tencent.smtt.export.external.interfaces.WebResourceRequest
import com.tencent.smtt.sdk.WebView
import com.tencent.smtt.sdk.WebViewClient

open class CustomizeWebViewClient(private val webHandler: WebHandler) : WebViewClient() {
    // >=7.0
    override fun shouldOverrideUrlLoading(wv: WebView?, request: WebResourceRequest?): Boolean {
        wv?.loadUrl(request?.url?.toString())
        return true

    }

    override fun shouldOverrideUrlLoading(wv: WebView?, url: String?): Boolean {
        wv?.loadUrl(url)
        return true
    }

    override fun onPageStarted(p0: WebView?, p1: String?, p2: Bitmap?) {
        super.onPageStarted(p0, p1, p2)
        webHandler.setLoadProgress(0)
    }

    override fun onPageFinished(p0: WebView?, p1: String?) {
        super.onPageFinished(p0, p1)
        webHandler.setLoadProgress(100)
        //        webHandler.getWebViewObservableData()?.loadProgress?.set(100)
    }
}